//
//  ViewController.swift
//  Swifit_Learn
//
//  Created by Clover on 2018/3/30.
//  Copyright © 2018年 youbing. All rights reserved.
//

import UIKit

struct subexample {
    let decrementer: Int
    subscript(index: Int) -> Int { // 下角标
        return decrementer / index
    }
}

enum Rank: Int {
    case ace = 1
    case two, three, four, five, six, seven, eight, nine, ten
    case jack, queen, king
    func simpleDescription() -> String {
        switch self {
        case .ace:
            return "ace"
        case .jack:
            return "jack"
        case .queen:
            return "queen"
        case .king:
            return "king"
        default:
            return String(self.rawValue)
        }
    }
}
class ViewController: UIViewController {
    @IBOutlet weak var click: UIButton!
    override func viewDidLoad() {
        super.viewDidLoad()
        let lable = "this label is "
        let width = 60.0;
        let name = "xiaoming"
        let labelWidthStr = lable + String(width)
        print("\(name):\(labelWidthStr)")
        self.arrayTest()
        self.switchTest()
        self.forinTest()
        print(self.greet("xiaoming", day: "firaday"))
        let statics = self.calculateStatistics(sources: [9,10,8,6,188,73,18])
        print("min:\(statics.min) max:\(statics.max) sum:\(statics.sum)")
        
        let ace = Rank.king
        let aceRawValue = ace.rawValue
        
        var userDefinedColorName: String? // defaults to nil
        var colorNameToUse = userDefinedColorName ?? "red"
        let sdfsf = [Int]()
        var threeDoubles = Array(repeating:10,count:10)
        let other = [10,10,29,200]
        var lastArr = other + threeDoubles
        lastArr.isEmpty
        lastArr.count
        for (index,item) in lastArr.enumerated() {
            print("index: \(index) item \(item)")
        }
        let someCharacter: Character = "z"
        switch someCharacter {
        case "a":
            print("a")
        case "z":
            print("hello:z")
        default:
            print(someCharacter)
        }
        
      print(self.sortedTest(nameArr: ["Chris","Alex","Ewa","Barry","Daniella"]))
        
        
        let division = subexample(decrementer: 100)
        print("100 除以 9 等于 \(division[9])")
        print("100 除以 2 等于 \(division[2])")
        print("100 除以 3 等于 \(division[3])")
        print("100 除以 5 等于 \(division[5])")
        print("100 除以 7 等于 \(division[7])")
    }
    
    
    
    
    @IBAction func click(_ sender: Any) {
        let vc : NExtViewController = NExtViewController()
        vc.age = 10;
        vc.name = "xiaoming";
        self.navigationController?.pushViewController(vc, animated: true)
    }
    @IBAction func tableViewVC(_ sender: Any) {
        let VC = CLOTableViewController()
        self.navigationController?.pushViewController(VC, animated: true)
    }
    
    func arrayTest(){
        let arr = ["one","tow","three","four"]
        let dic = ["one":"name","tow":"sex"]
        let emptyArr = [NSString]()
        let emptyDic = [NSString : NSString]()
    }
    
    func switchTest(){
        let vegetable = "red pepper"
        switch vegetable {
        case "celery":
            print("Add some raisins and make ants on a log.")
        case "cucumber", "watercress":
            print("That would make a good tea sandwich.")
        case let x where x.hasSuffix("pepper"):
            print("Is it a spicy \(x)?")
        default:
            print("Everything tastes good in soup.")
        }
    }
    
    func forinTest() {
        let numbersDic = ["Prime": [2, 3, 5, 7, 11, 13],
                       "Fibonacci": [1, 1, 2, 300, 5, 8],
                       "Square": [1, 4, 9, 16, 205],
                       ]
        var maxNum = 0
        for (_,numbers) in numbersDic {
            for number in numbers{
                if number > maxNum{
                    maxNum = number
                }
            }
        }
        print(maxNum)
    }
    
    func greet(_ name: NSString, day : NSString) -> String {
        return "Hello \(name) , today is \(day)"
    }
    
    func calculateStatistics(sources: [Int]) -> (min:Int, max:Int, sum:Int) {
        var min = sources[0]
        var max = sources[0]
        var sum = 0
        for source in sources {
            if min > source{
                min = source
            }
            if max < source{
                max = source
            }
            sum += source
        }
        return (min,max,sum)
    }
    
    func sortedTest(nameArr:[String]) -> [String] {
       return  nameArr.sorted { (s1: String,s2: String) -> Bool in return s1 < s2}
    }
    
    func backward(_ s1: String, _ s2: String) -> Bool {
        return s1 < s2
    }
    
    // ----------------------------------------------------------------------
    
    
}

